import { PageDto, PageData, PostMutiDto, PostMutiRes, PutDto, PutRes, PutMutiDto, DisableDto, DisableRes, PutMutiRes } from "~/rest";
import { getGateway } from "@/droplet-bus/core.define";

import { Gateway } from "@/droplet-bus/core.define";

import { app_gateway } from "./core.local";
import type { Contact, ContactGroup } from "./schema.contact";
import { PageResult } from "~/search";

export const ContactGroupGateway: Gateway = getGateway(app_gateway, "pond_contact_group");
export type putContactGroupDto = PutMutiDto<ContactGroup>;
export type disableContactGroupDto = DisableDto;

export interface ContactGroupInterfaceWithPrimary<T> {
  get(dto: T): Promise<PageResult<ContactGroup>>;

  /** 用户名称全系统中不允许重复 */
  put(dto: T & putContactGroupDto): Promise<PutMutiRes<ContactGroup>>;
  disable(dto: T & disableContactGroupDto): Promise<DisableRes>;
}

export const ContactGateway: Gateway = getGateway(app_gateway, "pond_contact");
export type getContactDto = PageDto<Contact> & { groupId: ContactGroup["id"] };
export type postContactDto = PostMutiDto<Contact> & { groupId: ContactGroup["id"] };
export type putContactDto = PutDto<Contact>;
export type disableContactDto = DisableDto;

export type searchContactDto = { keyword: string };
export type switchContactDto = PutMutiDto<{ contactId: Contact["id"]; targetGroupId: ContactGroup["id"] }>;

export interface ContactInterfaceWithDerive<T> {
  get(dto: T & getContactDto): Promise<PageData<Contact>>;
  post(dto: T & postContactDto): Promise<PostMutiRes<Contact>>;
  put(dto: T & putContactDto): Promise<PutRes<Contact>>;
  disable(dto: T & disableContactDto): Promise<DisableRes>;

  search(dto: T & searchContactDto): Promise<PageData<Contact>>;
  switch(dto: T & switchContactDto): Promise<null>;
}
